#include "ListOfCourses.h"


ListOfCourses::ListOfCourses(void)
{
	this->head =NULL;
}


ListOfCourses::~ListOfCourses(void)
{
	Course *temp = this->head;
	while (head) {
    temp = head;
    head = head->next;
    delete temp;
    }
}

string ListOfCourses::insert(string courseName, int amountOfStudents)
{
	Course *temp = new Course(courseName, amountOfStudents);
	temp->next = this->head;
	this->head = temp;
	return "Create Course Successfully";
}

void ListOfCourses::removeRecentCourse()
{
	Course *temp = this->head;
	this->head = this->head->next;
	delete temp;
}

void ListOfCourses::removeCourseAt(int pos)
{
	Course *current = this->head;
	Course *previous = this->head;

	if(current == NULL)
    {
        cout<<"Error "<<endl;
    }
    bool cont = true;
    int currentNumber = 0;
    do
    {
        if(currentNumber == pos)
        {

            previous->next = current->next;
            delete current;
            cont = false;
        }else
        {
            previous = current;
            current = current->next;
            currentNumber++;
        }
    }while(cont == true);
}

void ListOfCourses::display()
{
	Course *temp = this->head;

	while(temp!=NULL)
	{
		cout<<temp->courseName<<"\t\t"<<temp->amountOfStudents<<" Students Enrolled"<<endl;
		temp = temp->next;
	}
	cout<<endl;
}
